//app.js
import api from 'utils/api.js'

App({
  globalData: {
    userid: null,
    userInfo: []
  },
  onLaunch: function () {
    var that = this;
    that.userlogin();
  },
  userlogin: function () {
    var that = this;
    wx.login({
      success: function (res) {
        var js_code = res.code;
        wx.getUserInfo({
          success: function (res) {
            // console.log("用户信息", res)
            var nickName = res.userInfo.nickName;
            var avatarUrl = res.userInfo.avatarUrl;
            var userInfo = res.userInfo;
            that.globalData.userInfo = userInfo;
            api.wxLogin({
              data: {
                js_code: js_code,
                nickName: nickName,
                avatarUrl: avatarUrl
              },
              success: function (res) {
                // console.log('wxlogin', res)
                that.globalData.userid = res.data.result;

              }
            })
          }
        })
      }
    })
  }
})